"""
概率论5.1
大数定律:
    伯努利大数定律
"""
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import bernoulli

x = np.arange(1, 1001, 1)
p = 0.3
r = bernoulli.rvs(p, size=1000)
y = []
rsum = 0.0

for i in range(1000):
    if r[i] == 1:
        rsum = rsum + 1
    y.append(rsum / (i + 1) - p)
plt.plot(x, y, color='red')
plt.show()